<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>


    <link rel="stylesheet" type="text/css" href="/css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="/css/pages-register.css" />
	<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
	<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
	<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
	<script type="text/javascript" src="/js/pages/register.js"></script>
	<!--bootstrap-toastr-->
	<script type="text/javascript" src="/bootstrap/toastr/toastr.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/bootstrap/toastr/toastr.css">

	<script>
		// 手机验证码
		function getPhoneCode() {
			$.ajax({
				url : "/user/getPhoneCode",
				type : "post",
				data : {phoneNum : $("#phone").val()},
				dataType : "json",
				success : function (returnData) {
					if (returnData.code == 200) {
						toastr.success(returnData.message);
						var span = $("#phoneTimeOut");
						setTime(span);
					} else {
						toastr.error(returnData.message);
					}
				},
				error : function () {
					toastr.error("系统错误");
				}
			});
		}

		//60s倒计时实现逻辑
		var countdown = 60;
		function setTime(obj) {
			if (countdown == 0) {
				obj.prop('disabled', false);
				obj.html('<a href="javascript:getPhoneCode()">获取短信验证码</a>');
				countdown = 60;//60秒过后button上的文字初始化,计时器初始化;
				return;
			} else {
				obj.prop('disabled', true);
				obj.text("("+countdown+"s)后重新发送") ;
				countdown--;
			}
			setTimeout(function() { setTime(obj) },1000) //每1000毫秒执行一次
		}
		
		function userRegister() {
			$.ajax({
				url : "/user	/userRegister",
				type : "post",
				data : $("#registerUserForm").serialize(),
				dataType : "json",
				success : function (returnData) {
					if (returnData.code == 200) {
						setTimeout(function () {
							location.href = "/user/toUserLogin";
						}, 1500);
					} else if (returnData.code == 10) {
						toastr.success("手机验证码错误");
					} else {
						toastr.error(returnData.message);
					}
				},
				error : function (returnData) {
					toastr.error("系统错误");
					console.log(returnData);
				}
			})
		}
	</script>
</head>
<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="" class="logo-bd"></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="login.html" target="_blank">登陆</a></span></h3>
			<div class="info">
				<form class="sui-form form-horizontal" id="registerUserForm">
					<div class="control-group">
						<label class="control-label">用户名：</label>
						<div class="controls">
							<input type="text" name="username" placeholder="请输入你的用户名" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password"  placeholder="设置登录密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" name="password" placeholder="再次确认密码" class="input-xfat input-xlarge">
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" id="phone" name="phone" placeholder="请输入你的手机号" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">短信验证码：</label>
						<div class="controls">
							<input type="text" id="userCode" name="userCode" placeholder="短信验证码" class="input-xfat input-xlarge">
							<span id="phoneTimeOut"><a href="javascript:getPhoneCode()">获取短信验证码</a></span>
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked><span>同意协议并注册《东东商城用户协议》</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a class="sui-btn btn-block btn-xlarge btn-danger" href="javascript:userRegister();">完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机东东商城</li>
				<li>销售联盟</li>
				<li>东东商城社区</li>
			</ul>
			<div class="address">地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</div>
			<div class="beian">京ICP备08006666号京公网安备11010888888
			</div>
		</div>
	</div>
</body>

</html>